package group.raber.saber.kit;

import javax.servlet.http.HttpServletRequest;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by tisir<yangsong158@qq.com> on 2017-05-31
 */
public abstract class HttpKit {
    /**
     * 把请求数据中的map转换处理下,单个字串的直接以字串给返回出来
     * @param request
     * @return
     */
    public static Map<String,Object> getRequestParameterMap(HttpServletRequest request){
        Map<String,Object> retMap = new LinkedHashMap<String,Object>();

        Map<String, String[]> parameterMap = request.getParameterMap();
        Iterator<String> iterator = parameterMap.keySet().iterator();
        while (iterator.hasNext()){
            String name = iterator.next();
            String[] value = request.getParameterValues(name);
            if(value!=null&&value.length==1){
                retMap.put(name,value[0]);
            }else{
                retMap.put(name,value);
            }
        }


        return retMap;
    }
}
